#include <iostream>
#include <cmath>
using namespace std;
int direction = 0,up = 0, r = 0, n ;
void turn(int i ){
	direction += i;
	if(direction == 4 ) direction = 0;
	if(direction == -1) direction = 3;
}
int main()
{
	// 请在此输入您的代码
	cin >> n;
	// char x;
	for(int j = 0 ; j < n ; j ++)
	{
		string s;
		cin >> s;
		for(int i = 0 ;s[i] != '\0' ; i ++){
			if(s[i] == 'L'){
				turn(-1);
			}else if (s[i] == 'R'){
				turn(1);
			}else {
				switch(direction){
					case 0 : up ++; break;
					case 1 : r ++;break;
					case 2 : up --;break;
					case 3 : r --;break;
				}
			}
		}
		cout << sqrt(up * up + r *r) <<endl;
	}
	
	return 0;
}
